package com.xzsoft.gdwz.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping("/oauth2")
public class ServiceTest {	
	@RequestMapping(value = "/accessToken",method = {RequestMethod.POST})
	public void accessToken(HttpServletRequest request,HttpServletResponse response) throws IOException {
		String username = request.getParameter("username");
		System.out.println("username:"+username);
		response.setCharacterEncoding("UTF-8");  
		Map resultMap = new HashMap();
		Map map = new HashMap();
		map.put("uid", "22222");
		map.put("access_token", "access_token1");
		map.put("refresh_token", "refresh_token");
		map.put("time", "1381480688147");
		map.put("expires_in", "86400");
		map.put("refresh_token_expires", "1397205488147");
		resultMap.put("result", map);
		resultMap.put("resultCode", null);
		resultMap.put("success", true);
		resultMap.put("resultMessage", "");
		JSONObject jsonObject = JSONObject.fromObject(resultMap);
		response.getWriter().println(jsonObject.toString());
		response.getWriter().flush();  
		response.getWriter().close(); 
	}
	
	@RequestMapping(value = "/refreshToken",method = {RequestMethod.POST})
	public void refreshToken(HttpServletRequest request,HttpServletResponse response) throws IOException {
		String username = request.getParameter("access_token");
		System.out.println("username:"+username);
		response.setCharacterEncoding("UTF-8");  
		Map resultMap = new HashMap();
		Map map = new HashMap();
		map.put("uid", "22222");
		map.put("access_token", "access_token1");
		map.put("refresh_token", "refresh_token");
		map.put("time", "1381480688147");
		map.put("expires_in", "86400");
		map.put("refresh_token_expires", "1397205488147");
		resultMap.put("result", map);
		resultMap.put("resultCode", null);
		resultMap.put("success", true);
		resultMap.put("resultMessage", "");
		JSONObject jsonObject = JSONObject.fromObject(resultMap);
		response.getWriter().println(jsonObject.toString());
		response.getWriter().flush();  
		response.getWriter().close(); 
	}
	
}
